//
//  MyActivityIndicatorView.m
//  CarHome
//
//  Created by 莫晓芳 on 15-5-8.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "MyActivityIndicatorView.h"

@implementation MyActivityIndicatorView


+ (instancetype)addMyActivityIndicatorViewWithFrame:(CGRect)frame {
    UIView *view = [[[UIView alloc] initWithFrame:frame] autorelease];
    view.backgroundColor = [UIColor whiteColor];
    view.tag = 88;
    
    UIImageView *bottomView = [[[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)] autorelease];
    bottomView.center = CGPointMake(frame.size.width / 2, frame.size.height / 2);
    bottomView.image = [UIImage imageNamed:@"loadingpage_bg"];
    [view addSubview:bottomView];
    
    UIImageView *rotationView = [[[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)] autorelease];
    rotationView.center = CGPointMake(frame.size.width / 2, frame.size.height / 2);
    rotationView.image = [UIImage imageNamed:@"load_icon"];
    
    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI_2];
    rotationAnimation.duration = .5;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 10000;
    [rotationView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
    [view addSubview:rotationView];
    
    return (MyActivityIndicatorView *)view;
}

+ (void)removeMyActivityIndicatorViewFromView:(UIView *)view {
    UIView *myView = [view viewWithTag:88];
    [myView removeFromSuperview];
    [myView release];
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.bottomView = [[[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)] autorelease];
        _bottomView.center = CGPointMake(kWIDTH / 2, kHEIGHT / 2);
        _bottomView.image = [UIImage imageNamed:@"loadingpage_bg"];
        [self addSubview:_bottomView];
        
        self.rotationView = [[[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)] autorelease];
        _rotationView.center = CGPointMake(kWIDTH / 2, kHEIGHT / 2);
        _rotationView.image = [UIImage imageNamed:@"load_icon"];
        
        CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI_2];
        rotationAnimation.duration = .5;
        rotationAnimation.cumulative = YES;
        rotationAnimation.repeatCount = 10000;
        [_rotationView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
        [self addSubview:_rotationView];
    }
    return self;
}

@end
